package cn.virens.common.apifox;

import cn.hutool.core.util.ClassUtil;
import cn.virens.common.exception.APIException;

import java.util.Arrays;
import java.util.List;

public class ApifoxType {
    /**
     * 处理APIFOX对应的参数类型(允许为NULL)
     */
    public static List<String> formatNull(Class<?> clazz) throws APIException {
        return Arrays.asList(formatType(clazz), "null");
    }

    /**
     * 处理APIFOX对应的参数类型
     */
    public static String formatType(Class<?> clazz) throws APIException {
        return formatType(ClassUtil.getClassName(clazz, true));
    }

    /**
     * 处理APIFOX对应的参数类型
     */
    public static String formatType(String type) {
        return switch (type) {
            case "integer" -> "integer";
            case "string" -> "string";
            case "number" -> "number";
            case "object" -> "object";
            case "array" -> "array";

            case "Integer" -> "integer";
            case "Boolean" -> "boolean";
            case "String" -> "string";
            case "Double" -> "number";
            case "Short" -> "integer";
            case "Float" -> "number";
            case "Long" -> "integer";

            default -> "any";
        };
    }
}
